package coupon

import (
	"context"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/promotion/rpc/promotionclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type RestoreCouponTemplateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRestoreCouponTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RestoreCouponTemplateLogic {
	return &RestoreCouponTemplateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RestoreCouponTemplateLogic) RestoreCouponTemplate(req *types.IDsReq) (*types.BaseMsgResp, error) {
	if len(req.Ids) == 0 {
		return &types.BaseMsgResp{
			Success: true,
		}, nil
	}

	res, err := l.svcCtx.PromotionRpc.BackendRestoreCouponTemlate(l.ctx, &promotionclient.IDsReq{
		Ids: req.Ids,
	})
	if err != nil {
		return nil, err
	}

	return &types.BaseMsgResp{
		Success: true,
		Msg:     l.svcCtx.Trans.Trans(l.ctx, res.Msg),
	}, nil
}
